package com.enjoy.controller;

import com.enjoy.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

@Controller
public class IndexController {

    @Autowired
    ProductService productService;

    @ResponseBody
    @RequestMapping("/get")
    public String get(){
        return productService.get();
    }

    @RequestMapping("/printInfo")
    public String printInfo(HttpServletRequest request) {
        Cookie[] cookies = request.getCookies();

        if(cookies != null) {
            for (int i = 0; i < cookies.length; i++) {
                System.out.println("cookie name = >" + cookies[i].getName() + "= >" + "cookie value = " + cookies[i].getValue());
            }
        }

        Enumeration<String> headerNames = request.getHeaderNames();
        while(headerNames.hasMoreElements()) {
            String headername = headerNames.nextElement();
            System.out.println("header name = >" + headername + "= >" + "headervalue = " + request.getHeader(headername));
        }

        return this.getClass().getName()+"：abc";
    }
}
